<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div class="box">
    </div>
    <button class="back">上一页</button>
    <button class="next">下一页</button><span></span>
</body>

</html>
<script src="promise-ajax函数.js"></script>
<script src="表情包按钮函数.js"></script>
<script>
    // 定义一个变量，保存当前页码
    let page = 1;
    // 获取标签
    let box = document.querySelector('.box')
    box.style.display = 'flex'
    let btn1Ele = document.querySelector('.back')
    let btn2Ele = document.querySelector('.next')
    let spanEle = document.querySelector('span')
    //=============默认渲染一个页面,调用ajax函数
    ajax('get', `https://yantianfeng.com/api/emotion`, { page: page, count: 10 }).then((data) => {
        btn(data)
    })
    // =============上一页点击事件
    btn1Ele.onclick = function () {
        if (page > 1) {
            // 调用ajax函数，传入参数
            ajax('get', `https://yantianfeng.com/api/emotion`, { page: --page, count: 10 }).then((data) => {
                btn(data)
            })

        }
    }
    // =============下一页点击事件
    btn2Ele.onclick = function () {
        if (page < 4) {
            // 调用ajax函数，传入参数
            ajax('get', `https://yantianfeng.com/api/emotion`, { page: ++page, count: 10 }).then((data) => {
                btn(data)
            })
        }
    }
</script>